<%- include('layout/header.ejs') %>
<%- include('layout/top.ejs') %>
<%- include('layout/nav.ejs') %>
<%- include('layout/banner.ejs') %>
  <div class="page">
    <div class="p-center">
      <% if (config.source != 'gzh') { %>
      <ul class="pc-menu" style="margin-right: 44px;">
        <% type.forEach(item => { %>
        <li class="pcm-list">
          <a class="pcml-a <%= pathname == item.name ? 'active' : '' %>" href="<%= config.host %>/<%= item.name %>/" title="<%= item.title %>"><%= item.title %></a>
        </li>
        <% }) %>
      </ul>
      <% } %>
      <div class="pc-news">
        <ul class="pcn-ul">
          <% list.forEach(item => { %>
          <li class="pcnu-li">
            <a class="pcnul-title" href="<%= config.host %>/<%= pathname %>/<%= item.id %>.html" title="<%= item.title %>">&gt;<%= item.title %></a>
            <a class="pcnul-time" href="<%= config.host %>/<%= pathname %>/<%= item.id %>.html" title="<%= item.title %>"><%= item.publishedTimeNow %></a>
          </li>
          <% }) %>
        </ul>
        <div class="my-page">
          <ul class="mp-ul" id="page">
            <%
              let beforePage = parseInt(pageNum) - 1;
              let afterPage = parseInt(pageNum) + 1;
              if (pageNum > 1) {
                let prevPage = pageNum <= 2 ? '' : `p${beforePage}/`;
            %>
            <li class="mpu-li"><a class="mpul-a" href="<%= config.host %>/<%= pathname %>/<%= prevPage %>">上一页</a></li>
            <%  if (pageNum > 2 && pages > 4) { %>
            <li class="mpu-li"><a class="mpul-a" href="<%= config.host %>/<%= pathname %>/">1</a></li>
            <%  }
                if (pageNum > 3 && pages > 4) { %>
            <li class="mpu-li"><span class="spot">...</span></li>
            <%  } 
              }
              if (pageNum == pages) {
                beforePage = parseInt(beforePage) - 2;
              } else if (pageNum == parseInt(pages) - 1) {
                beforePage = parseInt(beforePage) - 1;
              }
              if (pageNum == 1) {
                afterPage = parseInt(afterPage) + 2;
              } else if (pageNum == 2) {
                afterPage = parseInt(afterPage) + 1;
              }
              for (let i = beforePage; i <= afterPage; i ++) {
                if (i > pages) {
                  continue;
                }
                if (i <= 0) {
                  i = i + 1;
                  if (beforePage < 1) {
                    i = 1
                  }
                }
                if (i == pageNum) {
            %>
            <li class="mpu-li"><span class="mpul-a active"><%= i %></span></li>
            <%  } else { %>
            <li class="mpu-li"><a class="mpul-a" href="<%= config.host %>/<%= pathname %>/p<%= i %>/"><%= i %></a></li>
            <%  }
              }
              if (pageNum < pages) {
                if (pages > 4) {
                  if (pageNum < pages - 1) {
                    if (pageNum < pages - 2) {
            %>
            <li class="mpu-li"><span class="spot">...</span></li>
            <%      } %>
            <li class="mpu-li"><a class="mpul-a" href="<%= config.host %>/<%= pathname %>/p<%= pages %>/"><%= pages %></a></li>
            <%    }
                }
                let nextPage = parseInt(pageNum) + 1;
            %>
            <li class="mpu-li"><a class="mpul-a" href="<%= config.host %>/<%= pathname %>/p<%= nextPage %>/">下一页</a></li>
            <% } %>
          </ul>
        </div>
      </div>
    </div>
  </div>
<%- include('layout/bottom.ejs') %>
<%- include('layout/footer.ejs') %>